package com.neusoft.service.impl;

import com.neusoft.dao.EmployeeDao;
import com.neusoft.dao.impl.EmployeeDaoImpl;
import com.neusoft.model.Employee;
import com.neusoft.service.EmployeeService;

import java.sql.SQLException;

public class EmployeeServiceImpl implements EmployeeService {
    private EmployeeDao employeeDao;
    //创建一个构造方法用于初始化对象
    public EmployeeServiceImpl() {
        employeeDao =  new EmployeeDaoImpl();
    }
    @Override
    public boolean save(Employee employee) {
        boolean isRight =  false;
        try {
            isRight = employeeDao.add(employee);
            //提交事务(数据真实有效的保存到数据库中)
        } catch (SQLException e) {
            //回滚(取消之前所有的操作)
            throw new RuntimeException(e);
        }
        return isRight;
    }
}
